$(function () {
    $('#dictionaryCode').focus();
    //重置表单
    $("#searchReset").on("click",function(){
        $('#dictionaryCode').val('');
        $('#dictionaryName').val('');
        $('#dictionaryTable').bootstrapTable('refresh');
    });
    //渲染表格
    var columns = dictionaryList.columnsInit();
    var table = dictionaryList.gridInit(columns);
    var datas = dictionaryList.dataInit();
    $("#dictionaryTable").bootstrapTable("append",datas);
    //点击删除按钮信息弹出框
    $("#del-btn").click(function(){
        var len = $("#dictionaryTable input:checked").length;
        if (len == 0) {
            //未选中数据提示框
            layer.msg('请选择数据',  {time:1000});
        } else {
            layer.confirm('确定要删除这条数据吗？',
                {icon: 3, title: '提示', area: '300px', btnAlign: 'c'}, function (index) {
                    layer.close(index);
                });
        }

    });
})
//新建弹框
function addDictionary(){
    layer.open({
        move: false,
        type: 2,
        title: '新建数据字典',
        area: ['800px', '350px'],
        content: 'j_dictionary_add.html',
        btn: ['保存','取消'],
        btnAlign: 'c',
        yes: function (index, layero) {
            var openWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            var form= openWin.submitForm();
            if(!form){
                layer.close(index);
            }
        }, cancel: function (index) {
            layer.close(index);
        }
    });
}
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var dictionaryList = {
        columnsInit:function(){
            return  [{
                field: 'od',
                title: '序号',
                width:'2%',
                align:'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },{
                field: 'dictionaryCode',
                valign: 'middle',
                title: '字典类型编号'
            }, {
                field: 'dictionaryName',
                valign: 'middle',
                title: '字典类型名称',
                sortable : true
            }, {
                field: 'rowSort',
                valign: 'middle',
                title: '排序号'
            },{
                field: 'status',
                title: '状态',
                valign: 'middle',
                align: 'center',
                formatter: function (value, row, index) {
                    if(value == '启用'){
                        return [
                            '<span class="sys-type-bg pro-status-green">启用</span>'
                        ];
                    }
                    return [
                        '<span class="sys-type-bg pro-status-red">异常</span>'
                    ];

                }

            },{
                checkbox: true
            },{
                field: 'option',
                title: '操作',
                width: 80,
                align: 'center',
                formatter: function (value, row, index) {
                    //up菜单向上展示、 down向下展示
                    var pageSize = dictionaryList.pageSize;
                    var cssStyle = 'bottom';
                    if (index > pageSize / 3) {
                        cssStyle = 'top';
                    }
                    return [
                        '<div class="opt-dropdown tb-opt-div"><a class="tb-opt-icon" href="javascript:void(0)">操作 <i class="glyphicon glyphicon-triangle-bottom"></i></a>',
                        '<ul class="opt-dropdown-menu opt-dropdown-menu-bottom">',
                        '<li><a href="j_task_add.html" title="编辑">',
                        '<i class="glyphicon glyphicon-pencil"></i><em> 编辑</em></a></li>',
                        '<li><a href="j_modify_list.html"><i class="qxticon icon-sblx"></i><em> 维护</em></a></li></ul></div>'
                    ].join('');
                }

            }]
        },
        gridInit:function(columns){
            return $("#dictionaryTable").bootstrapTable({
                url:'',
                columns: columns,
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                pageNumber: 1,
                pageSize: 10,
                pageList: [
                    10, 20, 50, 100
                ],
                onPostBody:function () {
                    $(".opt-dropdown").hover(function(){
                        $(this).find(".opt-dropdown-menu").show();
                    },function(){
                        $(this).find(".opt-dropdown-menu").hide();
                    })
                }
            })

        },
        dataInit:function(){
            return  [{
                od: '1',
                dictionaryCode: 'sfsf',
                dictionaryName:'电表-尖10:00-11:00',
                rowSort:'11:10:02',
                status:'启用'
            }]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = dictionaryList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return dictionaryList;});
    } else {
        !('plugin' in _global) && (_global.dictionaryList = dictionaryList);
    }
}());